#!/usr/local/bin/perl
use Image::Magick;

my( $bg, $image, $shadow, $grad, $gradb, $cloned, $x, $pin06, $pin07 );


#my $I = 0;
#my $minI = 0;
#my $maxI = $#ARGV;
#
#for ( $I = $minI; $I <= $maxI; $I++ ) {
# print( "@ARGV[ $I ] \n" );
#}

#if( $maxI < 2 ) {
# die;
#}

$image = Image::Magick->new;
$x = $image->Read( @ARGV[ 0 ] );
#$x = $image->Read( 'a.jpg' );
warn "$x" if "$x";

$bg = Image::Magick->new;
$x = $bg->Read( @ARGV[ 1 ] );
#$x = $bg->Read( 'a.bg.png' );
warn "$x" if "$x";

$x = $image->Trim();
warn "$x" if "$x";
$x = $image->Resize(geometry=>'230x170');
warn "$x" if "$x";
$x = $image->Set(bordercolor=>'gray');
warn "$x" if "$x";
$x = $image->Border(geometry=>'1x1');
warn "$x" if "$x";
$x = $image->Set(bordercolor=>'none');
warn "$x" if "$x";
$x = $image->Border(geometry=>'5');
warn "$x" if "$x";

$cloned = Image::Magick->new;
$cloned = $image->Clone();
warn "$x" if "$x";

$x = $cloned->Set(background=>'white');
warn "$x" if "$x";
$x = $cloned->Set(bordercolor=>'gray');
warn "$x" if "$x";
$x = $cloned->Composite( image=>$bg, compose=>'Xor', gravity=>'center');
warn "$x" if "$x";
$x = $cloned->Border(geometry=>'1x1');
warn "$x" if "$x";

$x = $cloned->Set(background=>'white');
warn "$x" if "$x";
$x = $cloned->Composite( image=>$image, compose=>'over', gravity=>'center');
warn "$x" if "$x";

$x = $cloned->Set(quality=>'80');
warn "$x" if "$x";
$x = $cloned->Strip();
warn "$x" if "$x";
$x = $cloned->Write(@ARGV[ 2 ]);
warn "$x" if "$x";

undef  $bg, $image, $shadow, $grad, $gradb, $cloned, $x, $pin06, $pin07;

